package com.example.innospace.demos.web.mapper;

import com.example.innospace.demos.pojo.dto.ProjectPageQueryDTO;
import com.example.innospace.demos.pojo.entity.Project;
import com.example.innospace.demos.pojo.vo.ProjectPageVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ProjectMapper {

    void save(@Param("project") Project project);


    /**
     * 通过队长id获得项目id
     * @param studentId
     * @return
     */
    @Select("select id from project where student_id=#{studentId}")
    Integer getIdBystudentId( @Param("studentId")String studentId);

    /**
     * 通过项目id查询项目
     * @param id
     * @return
     */
    @Select("select * from project where id=#{id}")
    Project getById(@Param("id")int id);

    /**
     * 分页
     * @param projectPageQueryDTO
     * @return
     */
    Page<ProjectPageVO> pageQuery(ProjectPageQueryDTO projectPageQueryDTO);

    /**
     * 通过id删除项目
     * @param projectId
     */
    @Delete("delete from project where id=#{projectId}")
    void deleteById( @Param("projectId")Integer projectId);

    /**
     * 设置项目级别
     * @param level
     * @param id
     */
    @Update("update project set level=#{level} where id=#{id}")
    void setLevel(@Param("level")String level, @Param("id")int id);

    /**
     * 根据id为项目设置级别
     * @param projectUUID
     * @param id
     */
    @Update("update project set projectUUID=#{projectUUID} where id=id")
    void setUUID(@Param("projectUUID") String projectUUID, @Param("id")int id);

    /**
     * 更新成员
     * @param studentId
     * @param id
     */
    @Update("update project set student_id=#{studentId} where id=#{id}")
    void updateStudentId( @Param("studentId")String studentId, @Param("id") int id);

    /**
     * 查看队员负责项目数
     * @param studentId
     * @return
     */
    @Select("SELECT COUNT(*) FROM project where student_id=#{studentId} ")
    Integer studentHoldProject(@Param("studentId")String studentId);

    /**
     * 更新项目级别
     * @param id
     * @param level
     */
    @Update("update project set level=#{level} where id=#{id}")
    void updateLevel(@Param("id")Integer id, @Param("level")String level);

    /**
     * 更新项目的UUID
     * @param id
     * @param projectUUID
     */
    @Update("update project set projectUUID=#{projectUUID} where id=#{id}")
    void updateProjectUUID(@Param("id")Integer id,@Param("projectUUID") String projectUUID);

    /**
     * 更新学校审核状态
     * @param projectId
     * @param isPassed
     */
    @Update("update project set is_passed=#{isPassed} where id=#{id}")
    void updateSchoolApprovalStatus(@Param("id") Integer projectId,@Param("isPassed") boolean isPassed);

    /**
     *
     * @param projectId
     * @param i
     */
    @Update("update  project set school_review_status=#{i} where id=#{id}")
    void setSchoolReviewStatus(@Param("id")Integer projectId,@Param("i") int i);

    /**
     * 设置学院审核状态
     * @param projectId
     * @param i
     */
    @Update("update  project set college_review_status=#{i} where id=#{id}")
    void setCollegeReviewStatus(@Param("id")Integer projectId,@Param("i") int i);

    /**
     * 更新
     * @param projectId
     * @param isPassed
     */
    @Update("update project set is_passed=#{isPassed} where id=#{id}")
    void updateCollegeApprovalStatus(@Param("id") Integer projectId, @Param("isPassed") boolean isPassed);

    @Update("update project set first_teacher=#{updaterId} where id=#{id}")
    void updateTeacherFirst(@Param("updaterId")String updaterId,@Param("id") Integer id);

    @Update("update project set second_teacher=#{updaterId} where id=#{id}")
    void updateTeacherSecond(@Param("updaterId")String updaterId,@Param("id")  Integer id);


    void updateProject(Project project);

    @Update("update project set is_project_extended=#{isProjectExtended} where id=#{projectId}")
    void setMidtermExtensionRequest(@Param("isProjectExtended")boolean isProjectExtended,@Param("projectId") Integer projectId);

    @Update("update project set is_midterm_application_submitted=#{b} where id=#{projectId}")
    void setis_midterm_application_submitted(@Param("b")boolean b, @Param("projectId")Integer projectId);

    @Update("update project set phase_type=#{phaseType} where id=#{projectId}")
    void updatePhaseType(@Param("phaseType") String phaseType, @Param("projectId")Integer projectId);
}
